package com.candiq.intercepter;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Timer;

import org.apache.commons.logging.Log;

import sun.io.Converters;

import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.TimerInterceptor;

public class MyTimerInterceptor extends TimerInterceptor {

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.opensymphony.xwork.interceptor.TimerInterceptor#intercept(com.
	 * opensymphony.xwork.ActionInvocation)
	 */
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		long startTime = System.currentTimeMillis();
		
		String result = super.intercept(invocation);

		long executedTime = System.currentTimeMillis() - startTime;
		recordTime(executedTime, result);
		return result;
	}

	private void recordTime(long timespan, String result) throws Exception {
		FileWriter fw = new FileWriter("c:\\tomcat.log", true);
		String content = "";
		content = String.valueOf(timespan);
		content += "ms";
		content += " ";
		content += result;
		content += " ";
		fw.write(content);
		fw.flush();
		fw.close();
		// throw new IOException("1234");
	}
}
